package com.example.singletonpattern.entity;

import java.util.Objects;

/**
 * @author ash
 * @description
 * @create 2023/2/21  21:08:51
 * @className SingletonThread
 * @verson 1.0.0
 */
public class SingletonThread {

    private static SingletonThread instance;

    private final static Object o = new Object();

    private SingletonThread() {
    }

    public static SingletonThread getInstance() {
        if (Objects.isNull(instance)) {
            synchronized (o) {
                //如果该对象为空，创建一个对象
                if (Objects.isNull(instance)) {
                    instance = new SingletonThread();
                }
            }
        }

        return instance;
    }
}
